import java.util.ArrayList;
import java.util.List;

public class ActionRecord {

	// private int playerId;
	private List<Integer> played;
	private List<Integer> drawn;
	private int playerType;
	private StrategyManager myManager;
	private int bluffRatio;
	private int bluffs;
	// measures straightforwardness in bluffs*100/rounds;
	private boolean bluffsNow;
	private boolean hasWinningHand;

	// boolean isActive;

	// 1 - TP
	// 2 - LP
	// 3 - TA
	// 4 - LA

	ActionRecord(StrategyManager manager) {
		myManager = manager;
		hasWinningHand = false;
		bluffsNow = false;
		played = new ArrayList<Integer>();
		drawn = new ArrayList<Integer>();
	}

	public void addBettingAction(int action) {
		played.add(action);
		if (played.size() > 50)
			played.remove(0);
	}

	public void addDrawingAcrion(int action) {
		drawn.add(action);
		if (drawn.size() > 50)
			drawn.remove(0);
	}

	public int getDrawingAction(int turn) {
		return drawn.get(turn);
	}

	public int getBiddingAcion(int turn) {
		return played.get(turn);
	}

	public int getLastBiddingAction() {
		return played.get(played.size() - 1);
	}

	public int evaluatePlayerType() {
		int foldCounter = 0;
		int raiseCounter = 0;
		int callCounter = 0;
		int checkCounter = 0;

		for (int p : played) {
			if (p == 0)
				foldCounter++;
			else if (p == 1)
				raiseCounter++;
			else if (p == 2)
				callCounter++;
			else if (p == 3)
				checkCounter++;
		}

		int openess = 0;
		int agressiveness = 0;

		if ((foldCounter * 100) / myManager.getRound() >= 60)
			openess = 0;
		else
			openess = 1;

		if (callCounter + checkCounter <= raiseCounter * 0.5)
			agressiveness = 3;
		else
			agressiveness = 1;

		playerType = agressiveness + openess;
		return playerType;

	}

	public int countDrawnCards() {
		int drawnCards = 0;
		if (drawn.size() > 2) {
			for (int i = 0; i < myManager.getDrawingNumber(); i++) {
				drawnCards = drawnCards + drawn.get(drawn.size() - 1 - i);
			}
		}
		return drawnCards;

	}

	public boolean hasWinningHand() {

		int drawnCards = countDrawnCards();

		if (drawnCards == 0) {
			if (bluffRatio <= 50)
				hasWinningHand = true;
			else
				hasWinningHand = false;
		} else
			hasWinningHand = false;

		return hasWinningHand;

	}

	public int getPlayerType() {
		return playerType;
	}

	public void bluffed() {
		bluffs++;
		bluffRatio = (bluffs * 100) / myManager.getRound();
	}
}
